home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Full / NetObjects Fusion 9 Standard / NOF9_Full_EN.exe / data1.cab / FSI / lib / nof / NOFSettings.js < prev    next >
Encoding:
Text File  |  2005-11-16  |  5.3 KB  |  191 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  NOFSettings.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24. if (!IS.isModuleInitialized("IS.NOF.NOFSettings"))
  25. {
  26.     
  27.     /****h* NOF_JavaScript_Library/NOF.NOFSettings
  28.     *
  29.     * NAME
  30.     *  NOF.NOFSettings
  31.     *
  32.     * DESCRIPTION
  33.     * Encapsulates Fusion NOFSettings  operations
  34.     *
  35.     * Sample of use:
  36.     *    var regEditObj = new NOF.NOFSettings();
  37.     *    var regBaseStr = regEditObj.getRegistryBase();
  38.     *    var versionStr = regEditObj.get("Version", NOF.NOFSettings.STRING_VALUE);
  39.     *    try {
  40.     *      var prevVersion = regEditObj.put("Version", "7.51.0000.5005");
  41.     *    } catch (e) {
  42.     *      alert( "error: "+e );
  43.     *    }
  44.     * 
  45.     * External dependencies: NOF.UTIL.Exception
  46.     ****/
  47.     
  48.     /**
  49.     * Constructor    
  50.     */  
  51.     function NOF_NOFSettings( ) {
  52.         this.__proto__ = NOF_NOFSettings.prototype;    
  53.         this.CLASS_NAME = "NOFSettings";     
  54.     }
  55.     {
  56.         var member = NOF_NOFSettings.prototype;
  57.         member.HKEY_LOCAL_MACHINE = true;      
  58.         
  59.         var method = NOF_NOFSettings.prototype;
  60.         
  61.         /**
  62.             * getRegistryBase
  63.             * @return the string defining the registry base key for the Fusion installation.
  64.         **/
  65.         method.getRegistryBase        = function () {
  66.             return NOF.App.getFSIApp().GetRegistryBase();
  67.         }
  68.         
  69.         /**
  70.         * get
  71.         * @param key - the registry key to search for. It can specify 
  72.         * a subfolder in the registry using backslash as delimiter. 
  73.         * The key is relative to the registry base key for Fusion.          
  74.         * @param type - type of the value specified by the key param. (NOF.NOFSettings.INT_VALUE or NOF.NOFSettings.STRING_VALUE)
  75.         * @return  the registry value (as string or int) or null if the key does not exist
  76.         **/
  77.         method.get                    = function ( key, type, notInLocalReg ) {
  78.             var ret = null;
  79.             var localMachine = this.HKEY_LOCAL_MACHINE;
  80.             if (notInLocalReg == true) {
  81.                 localMachine = !this.HKEY_LOCAL_MACHINE;
  82.             }
  83.             if (type == NOF.NOFSettings.INT_VALUE) {
  84.                 ret = NOF.App.getFSIApp().GetRegistryInt(localMachine, key);
  85.                 if (ret == 0) {
  86.                     ret = null;
  87.                 }
  88.             } else if (type == NOF.NOFSettings.STRING_VALUE) {
  89.                 ret = NOF.App.getFSIApp().GetRegistryString(localMachine, key);
  90.                 if ((ret != null) && (ret.length == 0)) {
  91.                     ret = null;            
  92.                 }
  93.             }                
  94.             /*
  95.             if ((ret == null) && (notInLocalReg != true)) {
  96.                 return this.get(key, type, true);
  97.             }
  98.             */
  99.             return ret;
  100.         }
  101.         
  102.         /**
  103.         * put
  104.         * @param key - the registry key whose value has to be modified. It can specify 
  105.         * a subfolder in the registry using backslash as delimiter. 
  106.         * The key is relative to the registry base key for Fusion.          
  107.         * @param value - new value
  108.         * @return previous value associated with specified key.
  109.         * @throws a NOF.UTIL.Exception if the key does not exist or the value is read only 
  110.         **/
  111.         method.put                    = function ( key, value ) {
  112.             var ret = null;
  113.             var backslashIndex = key.lastIndexOf("\\");
  114.             if ( backslashIndex > -1 ) {
  115.                 key = key.substring( backslashIndex + 1, key.length );
  116.             }
  117.             
  118.             try {
  119.                 eval("ret = NOF.App.getFSIApp()."+key);
  120.                 if ( (ret != null) && (ret != 'undefined') ) {
  121.                     eval("NOF.App.getFSIApp()."+key+" = value");                    
  122.                 } else {
  123.                     // maybe is a FSIApp2 member
  124.                     eval("ret = NOF.App.getFSIApp2()."+key);
  125.                     if ( (ret != null) && (ret != 'undefined') ) {
  126.                         eval("NOF.App.getFSIApp2()."+key+" = value");
  127.                     }
  128.                 }
  129.                 if ( ''+ret == 'undefined' ) {
  130.                     throw ( new NOF.UTIL.Exception("IllegalWrite") );
  131.                 }
  132.                 
  133.                 return ret;                
  134.                 
  135.             } catch(e) {
  136.                 //throw new NOF.IllegalWriteException(e.description);
  137.                 throw (new NOF.UTIL.Exception("IllegalWrite " + e.description));
  138.             }
  139.         }
  140.         
  141.         /**
  142.         * keys        
  143.         * @param pPath - the registry folder (relative to the Fusion key) to search for. 
  144.         * @return an Array object containing the keys found.
  145.         */
  146.         method.keys                    = function ( pPath ) {
  147.             return this.search( pPath, true);
  148.         }    
  149.         
  150.         /**
  151.         * values        
  152.         * @param pPath - the registry folder (relative to the Fusion key) to search for. 
  153.         * @return an Array object containing the values corresponding to the keys found in pPath registry.
  154.         */
  155.         method.values                = function ( pPath ) {
  156.             return this.search( pPath, false);
  157.         }    
  158.         
  159.         /**
  160.             * search
  161.         **/
  162.         method.search                = function ( pPath, pKeys) {
  163.             var ret = new Array();
  164.             var regIterator = new ActiveXObject(NOF.ProgId.FSIRegIterator);
  165.             regIterator.DefineSearch( this.HKEY_LOCAL_MACHINE, pPath, pKeys);
  166.             var tmp = "";
  167.             while (true) {
  168.                 tmp = regIterator.GetNext();
  169.                 if (tmp.length == 0)
  170.                     break;
  171.                 ret[ret.length] = tmp;
  172.             }
  173.             regIterator = null;
  174.             return ret;
  175.         }
  176.         /* 
  177.             method.getApp = function () {
  178.                 return NOF.App.getFSIApp();
  179.             }
  180.             
  181.             method.getApp2 = function () {
  182.                 return NOF.App.getFSIApp2();      
  183.             }
  184.         */
  185.     }    
  186.     
  187.     NOF.__proto__.NOFSettings  = NOF_NOFSettings;
  188.     
  189.     NOF.addVariable("NOFSettings.INT_VALUE", "Integer");
  190.     NOF.addVariable("NOFSettings.STRING_VALUE", "String");
  191. }